//
//  AddStaffJurisdictionCell.m
//  LogisticsSupplier
//
//  Created by 吕晶 on 2020/8/31.
//  Copyright © 2020 吕晶. All rights reserved.
//

#import "AddStaffJurisdictionCell.h"

@interface AddStaffJurisdictionCell ()

@property (nonatomic, strong) UIView *bgView;
@property (nonatomic, strong) UILabel *titleLab;
@property (nonatomic, strong) UILabel *lineLab;
@property (nonatomic, strong) UISwitch *changeSwitch;

@end

@implementation AddStaffJurisdictionCell

+ (instancetype)AddStaffJurisdictionCellWithTableView:(UITableView *)tableView {
    static NSString *cellID = @"AddStaffJurisdictionCell";
    AddStaffJurisdictionCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[AddStaffJurisdictionCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.backgroundColor = Color_backgroundColor;
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        self.bgView = [[UIView alloc] initWithFrame:CGRectMake(15, 0, ScreenW - 30, 60)];
        self.bgView.backgroundColor = HexColor(0xffffff);
        [self.contentView addSubview:self.bgView];
        
        self.lineLab = [[UILabel alloc] initWithFrame:CGRectMake(10, self.bgView.nim_height - 1, self.bgView.nim_width - 20, 1)];
        self.lineLab.backgroundColor = Color_backgroundColor;
        [self.bgView addSubview:self.lineLab];
        
        self.titleLab = [[UILabel alloc] initWithFrame:CGRectMake(10, 22.5, 120, 15)];
        self.titleLab.font = [UIFont systemFontOfSize:14];
        self.titleLab.textColor = HexColor(0x2B2C44);
        [self.bgView addSubview:self.titleLab];
        
        self.changeSwitch = [UISwitch new];
        self.changeSwitch.nim_width = 41;
        self.changeSwitch.nim_height = 25;
        self.changeSwitch.nim_left = self.bgView.nim_width - 15 - self.changeSwitch.nim_width;
        self.changeSwitch.nim_centerY = self.titleLab.nim_centerY;
        [self.changeSwitch addTarget:self action:@selector(switchChange:) forControlEvents:UIControlEventValueChanged];
        [self.bgView addSubview:self.changeSwitch];
        
        self.height = self.lineLab.nim_bottom;
    }
    return self;
}

- (void)switchChange:(UISwitch *)sender {
    if (self.changeBlock) {
        self.changeBlock();
    }
}


-(void)setTitle:(NSString *)title {
    _title = title;
    self.titleLab.text = title;
}

-(void)setShowLine:(BOOL)showLine {
    _showLine = showLine;
    self.lineLab.hidden = !showLine;
}

-(void)setIsCan:(BOOL)isCan {
    _isCan = isCan;
    self.changeSwitch.on = isCan;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
